package com.zhxh.nzpos.utils;

import android.app.Activity;
import android.content.Context;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.Window;

/**
 * Container for static utility methods
 */
public class DisplayUtil {

    /**
     * Uses the telephony manager to understand if the client is running on a
     * simulator or a real device. On the simulator the device id is a 15 chars
     * long 0 sequence (os < 2.1).
     * @param context the application Context
     * @return true if the device id is a 0s sequence, false otherwise.
     */
    public static boolean isSimulator(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(
                Context.TELEPHONY_SERVICE);
        String deviceId = tm.getDeviceId();
        return "000000000000000".equals(deviceId);
    }

    /**
     * @return checks if the sdcard is mounted
     */
    public static boolean isSDCardMounted() {
        return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    }

    /**
     * Convert a dimension in dip to px
     * @param dip
     * @param context
     * @return px
     */
	public static int dipToPx(final Context context, final int dip) {
		return (int) (dip * context.getResources().getDisplayMetrics().density + 0.5f);
	}

    /**
     * Convert a dimension from px to dip
     * @param px
     * @param context
     * @return dip
     */
    public static int pxToDip(int px, Context context) {
        return (int) (px / context.getResources().getDisplayMetrics().density);
    }
    
	public static DisplayMetrics getDisplayMetrics(final Activity activity) {
		final DisplayMetrics ret = new DisplayMetrics();
		activity.getWindowManager().getDefaultDisplay().getMetrics(ret);
		return ret;
	}

	public static DisplayMetrics getDisplayMetrics(final Context context) {
		return context.getResources().getDisplayMetrics();
	}
	
	public static void main(String[] args) {
		
	}
	
}

